package VAISFunc;
use strict;
use warnings 'all';
use PrlServer::API;

sub __VAIS_SFIRQ0{
  my($cli, $AIGh, $SFIRQh) = @_;
  $cli->clientPortOut (1);
  
  my $r = $AIGh->clientPortOut ($SFIRQh);
  if($r == -1){ $cli->clientPortOut ("From __VAIS_SFIRQ0 (): SFIRQ (interrupt request) for interrupt $SFIRQh failed!"); }
  else{ $cli->clientPortOut (" . "); }
}

sub __VAIS_SFIRQ1{
  my($cli, $AIGh, $SFIRQh) = @_;
  $cli->clientPortOut (2);
  my $r = $AIGh->clientPortOut ($SFIRQh);
  
  if($r == -1){ $cli->clientPortOut ("From __VAIS_SFIRQ1 (): SFIRQ (interrupt request) for interrupt $SFIRQh failed!"); }
  else{ $cli->clientPortOut (" . "); }
  
  $r = $AIGh->clientPortIn ();
  if($r == -1){ $cli->clientPortOut ("From __VAIS_SFIRQ1 (): failed to recieve data from AIG (maybe AIG is non-existent?)"); }
  else{ $cli->clientPortOut (" . "); }
  return $r;
}

sub __VAIS_SFIRQ2{
  my($cli, $AIGh, $SFIRQh, $data) = @_;
  $cli->clientPortOut (2);
  my $r = $AIGh->clientPortOut ($SFIRQh);
  
  if($r == -1){ $cli->clientPortOut ("From __VAIS_SFIRQ2 (): SFIRQ (interrupt request) for interrupt $SFIRQh failed!"); }
  else{ $cli->clientPortOut (" . "); }
  
  $r = $AIGh->clientPortOut ($data);
  
  if($r == -1){ $cli->clientPortOut ("From __VAIS_SFIRQ2 (): Failed to send data!"); }
  else{ $cli->clientPortOut (" . "); }
}

sub __os_clear_screen{
  my($AIGh) = shift;
  
  print __VAIS_SFIRQ1 ($AIGh, '0x90?006h');
}

sub __VAIS_getAIGHandle{
  my($cli, $AIGh) = @_;
  
  return __VAIS_SFIRQ1 ($cli, $AIGh, '0x90?000h');
}

sub __VAIS_dump{
  my($cli, $AIGh, $data) = @_;
  
  __VAIS_SFIRQ2 ($cli, $AIGh, '0x90?009h', $data);
}

sub __VAIS_halt{
  my($cli, $AIGh) = @_;
  
  __VAIS_SFIRQ0 ($cli, $AIGh, '0x90?003h $SPAIG$ '.$AIGh->{serverHost});
}

sub __VAIS_req_rel{
  my($cli, $AIGh) = @_;
  
  return __VAIS_SFIRQ1 ($cli, $AIGh, '0x90?00Ch');
}

1;
